
 const App = getApp()
// import itemData from './mock.js'
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')
//let bbb = [];

Page({
  data: {
    num: 1,
    itemData: [],
    orgid: "",
    userid: "",
    g_role: "",
    scrollHeight: 0,


  }, touchS: function (e) {  // touchstart
    let startX = App.Touches.getClientX(e)
    startX && this.setData({ startX })
  },
  touchM: function (e) {  // touchmove
    let itemData = App.Touches.touchM(e, this.data.itemData, this.data.startX)
    itemData && this.setData({ itemData })

  },
  touchE: function (e) {  // touchend
    const width = 150  // 定义操作列表宽度
    let itemData = App.Touches.touchE(e, this.data.itemData, this.data.startX, width)
    itemData && this.setData({ itemData })
  },
  itemDelete: function (e) {  // itemDelete
    let itemData = App.Touches.deleteItem(e, this.data.itemData)
    // console.log(e.currentTarget.dataset.hi);
    let params = { "ids": e.currentTarget.dataset.hi };
    //第三步 调用接口
    businessLogic.DeleteMessages(params, (res) => {
      //console.log(res);
      if (res == 1) {
        common.showToast("删除成功", "succeed");
      } else {
        common.showToast("删除失败", "fail");
      }

    });

    itemData && this.setData({ itemData })
  },

  onLoad: function (options) {
    var orgid = common.getStorageSync("orgid");
    var userid = common.getStorageSync("userid");
    var g_role = common.getStorageSync("role");
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });

    this.setData({
      orgid: orgid,
      userid: userid,
      g_role: g_role,
      scrollHeight: scrollHeight,
    });

    this.loadMore();

  }, inforDetail: function (e) {
    // console.log(e.currentTarget.dataset.hi);
    wx.navigateTo({
      url: "../inforDetail/inforDetail?id=" + e.currentTarget.dataset.hi
    });
  }, primary: function () {
    wx.navigateTo({
      url: "../addMation/addMation?name=" + this.data.g_title
    });
  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      this.loadMore();
    }
    else {
      common.showToast("已加载全部", "loading");
    }

  },
  
  scroll: function (event) {
    //该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。

  },
  topLoad: function (event) {
    //  该方法绑定了页面滑动到顶部的事件，然后做上拉刷新

  },
  loadMore: function (res) {
    common.showLoading("加载中", "loading");
    let params = { "page": this.data.num, "num": 15, "orgid": this.data.orgid, "userid": this.data.userid, };
    //第三步 调用接口
    businessLogic.QueryMessageList(params, (res) => {
      // console.log(res);
      var n = [];
      for (var i = 0; i < res.infos.length; i++) {
        if (res.infos[i].onclick > 999999) {
          // n[i] = Math.round((res[i].onclick / 100000) * 100) / 100;
          res.infos[i].onclick = 999999 + "+";
        } else {
          res.infos[i].onclick = res.infos[i].onclick + "次";
        }
      }
     // console.log(res)
      var bbb = this.data.itemData
      for (var a = 0; a < res.infos.length; a++) {
        bbb.push(res.infos[a]);
      }
      this.setData({
        itemData: bbb,
        lenpage: res.page.pages
      });
      common.hideLoading();
    });
  },
})  
